//
//  CXCollectionViewHeadReusableView.m
//  Travel
//
//  Created by dllo on 15/11/29.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "CXCollectionViewHeadReusableView.h"
#import "CXDestinationModel.h"

@interface CXCollectionViewHeadReusableView ()

@property (nonatomic, retain)UIView *view;
@property (nonatomic, retain)UILabel *titleLabel;
@property (nonatomic, retain)UILabel *blueLabel;
@property (nonatomic, strong) UIButton *btn_more;

@end

@implementation CXCollectionViewHeadReusableView

- (void)dealloc
{
    
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.view = [[UIView alloc]init];
        
        [self addSubview:self.view];
        
        self.titleLabel = [[UILabel alloc]init];
        [self.view addSubview:self.titleLabel];
        
        self.blueLabel = [[UILabel alloc]init];
        self.blueLabel.backgroundColor = [UIColor colorWithRed:0.4 green:0.78 blue:0.83 alpha:1];
        self.blueLabel.layer.masksToBounds = YES;
        self.blueLabel.layer.cornerRadius = 3;
        [self.view addSubview:self.blueLabel];
        
        self.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
        self.view.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.94 alpha:1];
        self.titleLabel.textColor = [UIColor darkGrayColor];
        
        self.btn_more = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.btn_more setImage:[UIImage imageNamed:@"allRight"] forState:UIControlStateNormal];
        [self.btn_more addTarget:self action:@selector(more) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:self.btn_more];
        
    }
    return self;
}


- (void)layoutSubviews
{
    self.view.frame = CGRectMake(0, 0, self.frame.size.width, 44);
    self.blueLabel.frame = CGRectMake(10, 10, 8, 24);
    self.titleLabel.frame = CGRectMake(self.blueLabel.frame.origin.x + 5 + 10, self.blueLabel.frame.origin.y, self.view.frame.size.width - 25, self.blueLabel.frame.size.height);
    
    self.btn_more.frame = CGRectMake(self.view.frame.size.width - 40, 10, 25, 25);
}

- (void)setModel_destination:(CXDestinationModel *)model_destination
{
    _model_destination = model_destination;
    self.titleLabel.text = self.model_destination.title;
    
    NSString *str = [NSString stringWithFormat:@"%@" , _model_destination.more];
    if ([str isEqualToString:@"1"]) {
        self.btn_more.hidden = NO;
    }else{
        self.btn_more.hidden = YES;
    }
    
}

- (void)more
{
    self.Index(self.model_destination.index);
}

@end
